/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;
import java.sql.*;
import java.util.*;
/**
 *
 * @author b2
 */
public class MySqlDataAccessHelper {
    private Connection connection;
    public void open(){
        try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            connection = DriverManager.getConnection("jdbc:odbc:qlcb");
        }catch(Exception ex){
            System.out.print(ex.getMessage());
        }
    }

    public void close(){
        try{
            this.connection.close();
        }catch(Exception ex){
        System.out.println(ex.getLocalizedMessage());
        }
    }

    public ResultSet executeQuery(String sql){
        ResultSet rs = null;
        try{
        Statement sm = this.connection.createStatement();
        rs = sm.executeQuery(sql);
        }catch(Exception ex){
        System.out.println(ex.getMessage());
        }
        return rs;
    }
    public int executeUpdate(String sql){
        int n = -1;
        try{
            Statement sm = this.connection.createStatement();
            n = sm.executeUpdate(sql);
        }catch(Exception ex){
        System.out.println(ex.getMessage());
        }
        return n;
    }
}
